<?php


namespace App\Http\Controllers\Estate;


use App\Http\Controllers\Controller;
use App\Models\EstateNav;
use Illuminate\Http\Request;

class NavController extends Controller
{
    public $model;

    public function __construct(){
        $this->model = new EstateNav();
    }

    /**
     *banner列表
     * @param Request $request
     * @return array
     */
    public function index(Request $request)
    {
        $user = $request->user();
        $param = $request->query();
        //查询当前物业自己添加的数据
        $where['status'] = 1;
        if (isset($param['title']) && !empty($param['title'])) $where[] = ['title','like',"%{$param['title:']}%"];
        return $this->success( $this->model->getList($where,'id','desc'));
    }

    /**
     * 新增
     * @param Request $request
     * @return array
     */
    public function store(Request $request)
    {
        $data = $request->post();
        return $this->model->create($data) ? $this->success('添加成功!') : $this->error('添加失败!');
    }

    /**
     * 获取详情
     * @param $id
     * @return array
     */
    public function show($id)
    {
        return $this->success( $this->model->getInfo(['id' => $id]) );
    }

    /**
     * 编辑
     * @param Request $request
     * @return array
     */
    public function update(Request $request)
    {
        $data = $request->post();
        return $this->model->edit( $data) ? $this->success('修改成功!') : $this->error('修改失败!');
    }

    /**
     * 删除
     * @param Request $request
     * @return array
     */
    public function destroy ($ids)
    {
        return $this->model->deletes( $ids ) ? $this->success('删除成功!') : $this->error('删除失败!');
    }

    /**
     *更改启用状态
     * @param int $id
     * @return \Illuminate\Http\Response
     */
    public function edit_show(Request $request)
    {
        $id = $request->post('id');
        $is_show = $this->model->getValue(['id' => $id],'is_show') == 1 ? 0 : 1;
        return $this->model->updateByWhere(['id' => $id],['is_show' => $is_show]) ? $this->success('修改成功!') : $this->error('修改失败!');
    }
}
